<?php
	if(empty($_POST['dir'])) die("manque le repertoire");
	$dir = $_POST['dir'];
	if (($dp = opendir($dir)) != false)
	{
		while (($file = readdir($dp)) != false)
		{
			$path = $dir.$file;
			if(is_dir($path)) continue;
			if($file[0]!="_" && $file[1]!=".")
				$list[filemtime($path)] = $file;
		}
		closedir($dp);
	}
	krsort($list);
	foreach($list as $file)
	{
		$full = $dir.$file;
		$tiny = $dir.'__'.$file;
		$display = $dir.'_'.$file;
		$tiny2 = substr($tiny,3);
		$display2 = substr($display,3);
		$full2 = substr($full,3);
		if (($size = @getimagesize($tiny)) == true)
		{
			$tw = $size[0];
			$th = $size[1];
		}
		if (($size = @getimagesize($display)) == true)
		{
			$dw = $size[0];
			$dh = $size[1];
		}
		if (($size = @getimagesize($full)) == true)
		{
			$fw = $size[0];
			$fh = $size[1];
		}
		
		echo '<li><table><td>';
		echo '<a href="'.$full.'">';
		if(file_exists($tiny)) echo '<img src="'.$tiny.'"></a>';
		else echo $file;
		echo '</a><td>';
		echo '<input type="button" onClick="addImg(\''.$full2.'\','.$fw.','.$fh.')" value="full">';
		if(file_exists($tiny))
		{
			echo '<br><input type="button" onClick="addImg(\''.$tiny2.'\','.$tw.','.$th.')" value="tiny">';
			echo '<br><input type="button" onClick="addImgLink(\''.$tiny2.'\','.$tw.','.$th.',\''.$full2.'\')" value="tiny > full">';
		}
		if(file_exists($display))
		{
			echo '<br><input type="button" onClick="addImg(\''.$display2.'\','.$dw.','.$dh.')" value="display">';
			if(file_exists($tiny))
				echo '<br><input type="button" onClick="addImgLink(\''.$tiny2.'\','.$tw.','.$th.',\''.$display2.'\')" value="tiny > display">';
			echo '<br><input type="button" onClick="addImgLink(\''.$display2.'\','.$dw.','.$dh.',\''.$full2.'\')" value="display > full">';
		}
		echo '<br><input type="button" onClick="deleteImg(\''.$dir.'\',\''.$file.'\')" value="supprimer">';
		echo '</table></li>';
	}
?>